//
// Created by chengs1r on 2021/11/11.
//

#include <stdio.h>

int getCounts (int num) {
    int count = 0;
    for (int i = 0; i < 32; ++i, num = num >> 1) {
        if (num & 0x1 == 1) {
            count++;
        }
    }
    return count;
}

int optimizeGetCounts (int num) {
    int count = 0;
    while (num) {
        count++;
        num = num & (num - 1);
    }
    return count;
}
int main () {
    int num = 20;
    printf("%d\n", getCounts(num));
    printf("%d\n", optimizeGetCounts(num));
    return 0;
}